<?php 
	include '../init.php';
	include ADMIN_PATH.'/header.php';

	$model=new Model('comments');
	//每页多少条
	$num=2;
	//查询总条数
	 $sql2="select count(*) 
		 	from 
			 	`comments` c,
		    `user`     u 
		    where 
		     c.uid=u.id
			 ";
	
	//总条数
	$total=$model->find($sql2)[0]['count(*)'];
	//var_dump($total);
	//总页数
	$pages=ceil($total/$num);
	//var_dump($pages);
	//获取当前页
	$p=$_GET['p']?$_GET['p']:1;
	//尾页处理
	$p=min($p,$pages);
	//首页处理
	$p=max($p,1);
	//上一页
	$prev=$p-1;
	//下一页
	$next=$p+1;

	//每页开始
	$start=($p-1)*$num;
	//每页结束(偏移量)
	$offset=$num;

	$sql="select
			c.id,
			c.text,
			c.status,
			c.comtime,
			u.username 
		   from 
		    `comments` c,
		    `user`     u 
		    where 
		     c.uid=u.id
		     limit $start,$offset
		    ";
	$list=$model->find($sql);

	$str="
		<a href='".ADMIN_URL."/comments/index.php' style=color:#abcdef;>首页</a>
		<a href='".ADMIN_URL."/comments/index.php?p=$prev' style=color:#abcdef;>上一页</a>
		<a href='".ADMIN_URL."/comments/index.php?p=$p' style=color:#abcdef;>$p</a>
		<a href='".ADMIN_URL."/comments/index.php?p=$next' style=color:#abcdef;>下一页</a>
		<a href='".ADMIN_URL."/comments/index.php?p=$pages' style=color:#abcdef;>尾页</a>
		";
?>
<div class="m_right">
	<div class="m_main">
		<h1 style="font:bold 26px/40px 宋体;">这是评论页面</h1>
		<table class="table" border="1" cellpadding="5" cellspacing="0" >
			
			<tr bgcolor="#ccc" height="50">
				<th>编号</th>
				<th>买家</th>
				<th>评论内容</th>
				<th>评论时间</th>
				<th>审核</th>
			</tr>
			<?php foreach ($list as $key => $value) :?>
				<tr>
					<td><?php echo $value['id']; ?></td>
					<td><?php echo $value['username'];?></td>
					<td><?php echo $value['text'];?></td>
					<td><?php echo date('Y年m月d日',$value['comtime']);?></td>
					<td>
						<?php echo $value['status']?'<a href="'.ADMIN_URL.'/comments/action.php?a=check&p='.$p.'&id='.$value['id'].'"><img style="width:60px;height:60px;border-radius:60px;" src="'.URL.'/public/images/dui.png"></a>':'<a href="'.ADMIN_URL.'/comments/action.php?a=check&p='.$p.'&id='.$value['id'].'"><img style="width:60px;height:60px;border-radius:60px;" src="'.URL.'/public/images/x.png"></a>';?>
						<!--<button>回复</button>-->
					</td>
				</tr>
			<?php endforeach;?>
			<tr>
				<th colspan="5" height="50px">
					<?php echo $str;?>
				</th>
			</tr>
		</table>
	</div>
</div>
<?php
	include ADMIN_PATH.'/footer.html';
?>